package com.lagou.interceptor;

import com.lagou.Utils.MyServletUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: springboot04_blog
 * @description: 统一处理前段请求的公共业务。
 * @author: zhoushiduo
 * @create: 2020-12-15 09:21
 */

@Service
public class MyHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Integer pageNum = 1, pageSize = 2;
        if(request.getParameter("pageNum") != null && !"".equals(request.getParameter("pageNum"))){
            pageNum = Integer.valueOf(request.getParameter("pageNum"));
        }
        if(request.getParameter("pageSize") != null && !"".equals(request.getParameter("pageSize"))){
            pageSize = Integer.valueOf(request.getParameter("pageSize"));
        }
        MyServletUtils.setLocalPageSysParm(pageNum,pageSize);
        return true;
    }
}
